#include <stdio.h>
#include <malloc.h>
#include <stdbool.h>

#define MAXSIZE 100
typedef struct  {
    int i,j;
    int pre;
} Box;
typedef struct {
    Box data[MAXSIZE];
    int front,rear;
} SqQueue;
SqQueue initQueue(SqQueue *Q,Box box) {
    SqQueue *queue;
    queue = (SqQueue*)malloc(sizeof (SqQueue));
    queue->data[0] = box;
    queue->front = 0;
    queue->rear = 1;
    return *queue;

}
bool isFull(SqQueue *Q){
    return ((Q->rear+1)%MAXSIZE == Q->front);
}
bool addQ(SqQueue *Q,Box box) {
    if(isFull(Q)) {
        printf("队列满!");
        return false;
    }
    Q->data[Q->rear] = box;
    Q->rear = (Q->rear + 1)%MAXSIZE;
    return true;
}
bool DeleteQ(SqQueue *Q) {
    Q->front = (Q->front + 1)%MAXSIZE;
    return true
}
Box Peek(SqQueue *Q) {
    Box  box = Q->data[Q->front];
    return box;
}
bool BFT(int arr[10][10],SqQueue *Q) {
    Box *box1,*box2,*box3,*box4;
    box1 = (Box*) malloc(sizeof (Box));
    box2 = (Box*) malloc(sizeof (Box));
    box3 = (Box*) malloc(sizeof (Box));
    box4 = (Box*) malloc(sizeof (Box));
    if(arr[Peek(Q).i-1][Peek(Q).j] == 0 || arr[Peek(Q).i-1][Peek(Q).j] == 1) {
        box1->i = Peek(Q).i - 1;
        box1->j = Peek(Q).j;
        box1->pre = Q->front;
        addQ(Q,*box1);
        if( arr[Peek(Q).i-1][Peek(Q).j] == 1) {
            return true;
        }
        arr[Peek(Q).i-1][Peek(Q).j] = 2;
    }
    if (arr[Peek(Q).i][Peek(Q).j + 1] == 0 || arr[Peek(Q).i][Peek(Q).j + 1] == 1) {
        box2->i = Peek(Q).i ;
        box2->j = Peek(Q).j + 1;
        box2->pre = Q->front;
        addQ(Q,*box2);
        if( arr[Peek(Q).i][Peek(Q).j + 1] == 1) {
            return true;
        }
        arr[Peek(Q).i][Peek(Q).j + 1] =2;
    }
    if (arr[Peek(Q).i + 1][Peek(Q).j] == 0 || arr[Peek(Q).i + 1][Peek(Q).j] == 1) {
        box3->i = Peek(Q).i +1 ;
        box3->j = Peek(Q).j;
        box3->pre = Q->front;
        addQ(Q,*box3);
        if( arr[Peek(Q).i + 1][Peek(Q).j] == 1) {
            return true;
        }
        arr[Peek(Q).i + 1][Peek(Q).j] = 2;
    }
    if (arr[Peek(Q).i][Peek(Q).j - 1] == 0 || arr[Peek(Q).i][Peek(Q).j - 1] == 1) {
        box4->i = Peek(Q).i ;
        box4->j = Peek(Q).j - 1;
        box4->pre = Q->front;
        addQ(Q,*box4);
        if( arr[Peek(Q).i][Peek(Q).j - 1] == 1) {
            return true;
        }
        arr[Peek(Q).i][Peek(Q).j - 1] =2;
    }
    DeleteQ(Q);
    BFT(arr,Q);
}
void reBFT(SqQueue *queue,int arr[10][10]) {
    int index = queue->data[queue->rear - 1].pre;
    while (index != -1) {
        arr[queue->data[index].i][queue->data[index].j] = 4;
        index = queue->data[index].pre;
    }
}
void printBFT(int arr[10][10]) {
    printf("======8*8迷宫=====\n");
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            switch (arr[i][j]) {
                case 8:
                    printf("围");
                    break;
                case 6:
                    printf("囚");
                    break;
                case 0:
                    printf("　");
                    break;
                case 4:
                    printf("＞");
                    break;
                case 2:
                    printf("／");
                    break;
                case 1:
                    printf("回");
                    break;
            }
        }
        printf("\n");
    }
}
int main() {
    printf("Hello, World!\n");
    return 0;
}
